﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LockCrypt.Core {
    /// <summary>
    /// A container for multiple exceptions.
    /// </summary>
    public class MultipleException : Exception {
        /// <summary>
        /// Gets or sets whether this MultipleException is fatal.
        /// </summary>
        /// <value><c>true</c> if this MultipleException is fatal, otherwise <c>false</c>.</value>
        public bool IsFatal { get; set; }

        /// <summary>
        /// Gets or sets the exceptions.
        /// </summary>
        /// <value>The exceptions.</value>
        public List<Exception> Exceptions { get; set; }

        /// <summary>
        /// Gets or sets the error messages in this exception.
        /// </summary>
        /// <value>The errors messages.</value>
        [Obsolete("Use Exceptions property instead")]
        public List<string> Errors {
            get { return Exceptions.Select(ex => ex.Message).ToList(); }
            private set {
                Exceptions.Add(new Exception());
            }
        }

        /// <summary>
        /// Initializes a new <see cref="MultipleException"/>.
        /// </summary>
        public MultipleException() {
            this.Exceptions = new List<Exception>();
            this.IsFatal = false;
        }

        /// <summary>
        /// Initializes a new <see cref="MultipleException"/>.
        /// </summary>
        /// <param name="exceptions">The exceptions.</param>
        public MultipleException(List<Exception> exceptions)
            :this() {
            this.Exceptions = exceptions;
        }
    }
}
